package com.grablist.feihu.grablist.ui.actviity.user;

import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;

import com.superrecycleview.superlibrary.recycleview.ProgressStyle;
import com.superrecycleview.superlibrary.recycleview.SuperRecyclerView;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import butterknife.Bind;
import com.grablist.feihu.grablist.R;
import com.grablist.feihu.grablist.base.BaseActivity;
import com.grablist.feihu.grablist.bean.BillInfo;
import com.grablist.feihu.grablist.event.NetErrorEvent;
import com.grablist.feihu.grablist.ui.actviity.user.biz.BillBiz;
import com.grablist.feihu.grablist.ui.actviity.user.component.DaggerBillComponent;
import com.grablist.feihu.grablist.ui.actviity.user.contract.BillContract;
import com.grablist.feihu.grablist.ui.actviity.user.module.BillModule;
import com.grablist.feihu.grablist.ui.actviity.user.presenter.BillPresenter;
import com.grablist.feihu.grablist.ui.adapter.BillAdapter;

/**
 * Created by admin on 2017/12/2.
 */

public class BillAct extends BaseActivity implements BillContract.View, SuperRecyclerView.LoadingListener {


    @Bind(R.id.super_recycler_view)
    SuperRecyclerView superRecyclerView;

    BillAdapter adapter;

    @Inject
    BillPresenter presenter;
    @Inject
    BillBiz biz;

    private List<BillInfo> dataList = new ArrayList<>();

    @Override
    protected void setRoot() {
        setTitleBar("#FFFFFFFF");
        setContentView(R.layout.activity_collection);
    }

    @Override
    protected void setup() {
        setStateText();
        setToolBar("我的账单", "");
        DaggerBillComponent.builder().billModule(new BillModule(this)).build().inject(this);
        presenter.setBiz(biz);

    }


    @Override
    protected void init(@Nullable Bundle savedInstanceState) {
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        superRecyclerView.setLayoutManager(layoutManager);
        superRecyclerView.setRefreshEnabled(false);// 可以定制是否开启下拉刷新
        superRecyclerView.setLoadMoreEnabled(false);// 可以定制是否开启加载更多
        superRecyclerView.setLoadingListener(this);// 下拉刷新，上拉加载的监听
        superRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);// 下拉刷新的样式
        superRecyclerView.setLoadingMoreProgressStyle(ProgressStyle.BallClipRotate);// 上拉加载的样式
        superRecyclerView.setArrowImageView(R.mipmap.iconfont_downgrey);// 设置下拉箭头
        presenter.getBillList();
    }


    @Override
    public void onNetErrorEvent(NetErrorEvent event) {
        super.onNetErrorEvent(event);
    }

    @Override
    protected void onNetError(NetErrorEvent event) {

    }
    /***
     * Stop location service
     */
    @Override
    protected void onStop() {

        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        biz.onDestory();
    }




    @Override
    public void onRefresh() {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                superRecyclerView.completeRefresh();
            }
        }, 3000);
    }

    @Override
    public void onLoadMore() {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                superRecyclerView.completeLoadMore();
            }
        }, 3000);
    }


    @Override
    public void updateBill(List<BillInfo> coupons) {
        if (adapter == null) {
            adapter = new BillAdapter(this, coupons);
            superRecyclerView.setAdapter(adapter);
        } else {
            adapter.notifyDataSetChanged();
        }
    }

    @Override
    public void refreshComplete() {
        superRecyclerView.completeRefresh();
    }

    @Override
    public void loadMoreComplete() {
        superRecyclerView.completeLoadMore();
    }

    @Override
    public void hasLoadMore(boolean b) {
        superRecyclerView.setNoMore(b);
    }
}
